<?php
class Answer extends AppModel {
	var $name = 'Answer';
	var $displayField = 'body';
	
	const BEST = 2; // best answer
	const HELPFUL = 1; // helpfull answerr
	
	const BEST_SCORE = 30; // score for best answer
	const HELPFUL_SCORE = 10; // score for helpful answer
	
	var $validate = array(
		'user_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'body' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'user_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Question' => array(
			'className' => 'Question',
			'foreignKey' => 'question_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
	
	public function status($answer)
	{
		switch ($answer['Answer']['marked_as']) {
			case Answer::BEST:
				return '最佳答案';
				break;
			case Answer::HELPFUL:
				return '有帮助';
				break;
			case 0:
				return '';
				break;
			
			default:
				return '待解决';
				break;
		}		
	}
}
?>